package top.eggcode.config.jpa.datasource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import top.eggcode.component.mds.DsContextHolder;


public class SimpleRoutingDataSource extends AbstractRoutingDataSource {

    private static final Logger log = LoggerFactory.getLogger(SimpleRoutingDataSource.class);

    @Override
    protected Object determineCurrentLookupKey() {
        String dsName = DsContextHolder.getName();
        log.info("Use DataSource name: ".concat(dsName == null ? "default" : dsName));
        return DsContextHolder.getName();
    }
}
